home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_008 / src / hack.do_wear.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  7KB  |  305 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* hack.do_wear.c version 1.0.1 - changed an int to long */
  3.  
  4. #include "hack.h"
  5. #include <stdio.h>
  6. extern char *nomovemsg;
  7.  
  8. off_msg(otmp) register struct obj *otmp; {
  9.     pline("You were wearing %s.", doname(otmp));
  10. }
  11.  
  12. doremarm() {
  13.     register struct obj *otmp;
  14.     if(!uarm && !uarmh && !uarms && !uarmg) {
  15.         pline("Not wearing any armor.");
  16.         return(0);
  17.     }
  18.     otmp = (!uarmh && !uarms && !uarmg) ? uarm :
  19.         (!uarms && !uarm && !uarmg) ? uarmh :
  20.         (!uarmh && !uarm && !uarmg) ? uarms :
  21.         (!uarmh && !uarm && !uarms) ? uarmg :
  22.         getobj("[", "take off");
  23.     if(!otmp) return(0);
  24.     if(!(otmp->owornmask & (W_ARMOR - W_ARM2))) {
  25.         pline("You can't take that off.");
  26.         return(0);
  27.     }
  28.     (void) armoroff(otmp);
  29.     return(1);
  30. }
  31.  
  32. doremring() {
  33.     if(!uleft && !uright){
  34.         pline("Not wearing any ring.");
  35.         return(0);
  36.     }
  37.     if(!uleft)
  38.         return(dorr(uright));
  39.     if(!uright)
  40.         return(dorr(uleft));
  41.     if(uleft && uright) while(1) {
  42.         pline("What ring, Right or Left? ");
  43.         switch(readchar()) {
  44.         case ' ':
  45.         case '\n':
  46.         case '\033':
  47.             return(0);
  48.         case 'l':
  49.         case 'L':
  50.             return(dorr(uleft));
  51.         case 'r':
  52.         case 'R':
  53.             return(dorr(uright));
  54.         }
  55.     }
  56.     /* NOTREACHED */
  57. #ifdef lint
  58.     return(0);
  59. #endif lint
  60. }
  61.  
  62. dorr(otmp) register struct obj *otmp; {
  63.     if(cursed(otmp)) return(0);
  64.     ringoff(otmp);
  65.     off_msg(otmp);
  66.     return(1);
  67. }
  68.  
  69. cursed(otmp) register struct obj *otmp; {
  70.     if(otmp->cursed){
  71.         pline("You can't. It appears to be cursed.");
  72.         return(1);
  73.     }
  74.     return(0);
  75. }
  76.  
  77. armoroff(otmp) register struct obj *otmp; {
  78. register int delay = -objects[otmp->otyp].oc_delay;
  79.     if(cursed(otmp)) return(0);
  80.     setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);
  81.     if(delay) {
  82.         nomul(delay);
  83.         switch(otmp->otyp) {
  84.         case HELMET:
  85.             nomovemsg = "You finished taking off your helmet.";
  86.             break;
  87.         case PAIR_OF_GLOVES:
  88.             nomovemsg = "You finished taking off your gloves";
  89.             break;
  90.         default:
  91.             nomovemsg = "You finished taking off your suit.";
  92.         }
  93.     } else {
  94.         off_msg(otmp);
  95.     }
  96.     return(1);
  97. }
  98.  
  99. doweararm() {
  100.     register struct obj *otmp;
  101.     register int delay;
  102.     register int err = 0;
  103.     long mask = 0;
  104.  
  105.     otmp = getobj("[", "wear");
  106.     if(!otmp) return(0);
  107.     if(otmp->owornmask & W_ARMOR) {
  108.         pline("You are already wearing that!");
  109.         return(0);
  110.     }
  111.     if(otmp->otyp == HELMET){
  112.         if(uarmh) {
  113.             pline("You are already wearing a helmet.");
  114.             err++;
  115.         } else
  116.             mask = W_ARMH;
  117.     } else if(otmp->otyp == SHIELD){
  118.         if(uarms) pline("You are already wearing a shield."), err++;
  119.         if(uwep && uwep->otyp == TWO_HANDED_SWORD)
  120.     pline("You cannot wear a shield and wield a two-handed sword."), err++;
  121.         if(!err) mask = W_ARMS;
  122.     } else if(otmp->otyp == PAIR_OF_GLOVES){
  123.         if(uarmg) pline("You are already wearing gloves."); else
  124.         if(uwep && uwep->cursed)
  125.             pline("You cannot wear gloves over your weapon.");
  126.         else mask = W_ARMG;
  127.     } else {
  128.         if(uarm) {
  129.             if(otmp->otyp != ELVEN_CLOAK || uarm2) {
  130.                 pline("You are already wearing some armor.");
  131.                 err++;
  132.             }
  133.         }
  134.         if(!err) mask = W_ARM;
  135.     }
  136.     if(err) return(0);
  137.     setworn(otmp, mask);
  138.     if(otmp == uwep)
  139.         setuwep((struct obj *) 0);
  140.     delay = -objects[otmp->otyp].oc_delay;
  141.     if(delay){
  142.         nomul(delay);
  143.         nomovemsg = "You finished your dressing manoeuvre.";
  144.     }
  145.     otmp->known = 1;
  146.     return(1);
  147. }
  148.  
  149. dowearring() {
  150.     register struct obj *otmp;
  151.     long mask = 0;
  152.     long oldprop;
  153.  
  154.     if(uleft && uright){
  155.         pline("There are no more ring-fingers to fill.");
  156.         return(0);
  157.     }
  158.     otmp = getobj("=", "wear");
  159.     if(!otmp) return(0);
  160.     if(otmp->owornmask & W_RING) {
  161.         pline("You are already wearing that!");
  162.         return(0);
  163.     }
  164.     if(otmp == uleft || otmp == uright) {
  165.         pline("You are already wearing that.");
  166.         return(0);
  167.     }
  168.     if(uleft) mask = RIGHT_RING;
  169.     else if(uright) mask = LEFT_RING;
  170.     else do {
  171.          pline("What ring-finger, Right or Left? ");
  172.         switch(readchar()){
  173.         case 'l':
  174.         case 'L':
  175.             mask = LEFT_RING;
  176.             break;
  177.         case 'r':
  178.         case 'R':
  179.             mask = RIGHT_RING;
  180.             break;
  181.         case ' ':
  182.         case '\n':
  183.         case '\033':
  184.             return(0);
  185.         }
  186.     } while(!mask);
  187.     setworn(otmp, mask);
  188.     if(otmp == uwep)
  189.         setuwep((struct obj *) 0);
  190.     oldprop = u.uprops[PROP(otmp->otyp)].p_flgs;
  191.     u.uprops[PROP(otmp->otyp)].p_flgs |= mask;
  192.     switch(otmp->otyp){
  193.     case RIN_LEVITATION:
  194.         if(!oldprop) float_up();
  195.         break;
  196.     case RIN_PROT_SHAPE_CHANGERS:
  197.         rescham();
  198.         break;
  199.     case RIN_GAIN_STRENGTH:
  200.         u.ustr += otmp->spe;
  201.         u.ustrmax += otmp->spe;
  202.         flags.botl=1;
  203.         break;
  204.     case RIN_INCREASE_DAMAGE:
  205.         u.udaminc += otmp->spe;
  206.         break;
  207.     }
  208.     prinv(otmp);
  209.     return(1);
  210. }
  211.  
  212. ringoff(obj)
  213. register struct obj *obj;
  214. {
  215. register long mask;
  216.     mask = obj->owornmask & W_RING;
  217.     setworn((struct obj *) 0, obj->owornmask);
  218.     if(!(u.uprops[PROP(obj->otyp)].p_flgs & mask)){
  219.         pline("Strange... I didnt know you had that ring.");
  220.         impossible();
  221.     }
  222.     u.uprops[PROP(obj->otyp)].p_flgs &= ~mask;
  223.     switch(obj->otyp) {
  224.     case RIN_LEVITATION:
  225.         if(!Levitation) {    /* no longer floating */
  226.             float_down();
  227.         }
  228.         break;
  229.     case RIN_GAIN_STRENGTH:
  230.         u.ustr -= obj->spe;
  231.         u.ustrmax -= obj->spe;
  232.         flags.botl = 1;
  233.         break;
  234.     case RIN_INCREASE_DAMAGE:
  235.         u.udaminc -= obj->spe;
  236.         break;
  237.     }
  238. }
  239.  
  240. find_ac(){
  241. register int uac = 10;
  242.     if(uarm) uac -= uarm->spe;
  243.     if(uarm2) uac -= uarm2->spe;
  244.     if(uarmh) uac -= uarmh->spe;
  245.     if(uarms) uac -= uarms->spe;
  246.     if(uarmg) uac -= uarmg->spe;
  247.     if(uleft && uleft->otyp == RIN_PROTECTION) uac -= uleft->spe;
  248.     if(uright && uright->otyp == RIN_PROTECTION) uac -= uright->spe;
  249.     if(uac != u.uac){
  250.         u.uac = uac;
  251.         flags.botl = 1;
  252.     }
  253. }
  254.  
  255. glibr(){
  256. register struct obj *otmp;
  257. int xfl = 0;
  258.     if(!uarmg) if(uleft || uright) {
  259.         /* Note: at present also cursed rings fall off */
  260.         pline("Your %s off your fingers.",
  261.             (uleft && uright) ? "rings slip" : "ring slips");
  262.         xfl++;
  263.         if(otmp = uleft){
  264.             ringoff(uleft);
  265.             dropx(otmp);
  266.         }
  267.         if(otmp = uright){
  268.             ringoff(uright);
  269.             dropx(otmp);
  270.         }
  271.     }
  272.     if(otmp = uwep){
  273.         /* Note: at present also cursed weapons fall */
  274.         setuwep((struct obj *) 0);
  275.         dropx(otmp);
  276.         pline("Your weapon %sslips from your hands.",
  277.             xfl ? "also " : "");
  278.     }
  279. }
  280.  
  281. struct obj *
  282. some_armor(){
  283. register struct obj *otmph = uarm;
  284.     if(uarmh && (!otmph || !rn2(4))) otmph = uarmh;
  285.     if(uarmg && (!otmph || !rn2(4))) otmph = uarmg;
  286.     if(uarms && (!otmph || !rn2(4))) otmph = uarms;
  287.     return(otmph);
  288. }
  289.  
  290. corrode_armor(){
  291. register struct obj *otmph = some_armor();
  292.     if(otmph){
  293.         if(otmph->rustfree ||
  294.            otmph->otyp == ELVEN_CLOAK ||
  295.            otmph->otyp == LEATHER_ARMOR ||
  296.            otmph->otyp == STUDDED_LEATHER_ARMOR) {
  297.             pline("Your %s not affected!",
  298.                 aobjnam(otmph, "are"));
  299.             return;
  300.         }
  301.         pline("Your %s!", aobjnam(otmph, "corrode"));
  302.         otmph->spe--;
  303.     }
  304. }
  305.